package me.zhengjie.modules.member.rest;

import com.qiaofang.applet.service.member.service.AppointmentService;
import com.qiaofang.applet.service.member.service.dto.AppointmentEditDto;
import com.qiaofang.applet.service.member.service.dto.AppointmentQueryDto;
import com.qiaofang.applet.service.member.service.dto.AppointmentResponseDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.modules.system.service.UserService;
import me.zhengjie.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * @Author YuLing.Ou
 * @DATE 2021/1/15 14:13
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "其他：预约管理")
@RequestMapping("/api/appointment")
public class AppointmentController {

    @Autowired
    private AppointmentService appointmentService;

    @Autowired
    private UserService userService;

    @GetMapping
    @ApiOperation(value = "查询预约列表", notes = "查询预约列表")
    public ResponseEntity<Page<AppointmentResponseDto>> list (AppointmentQueryDto appointmentQueryDto, Pageable pageable){
        appointmentQueryDto.setCorporationCode(SecurityUtils.getCorporationCode());
        appointmentQueryDto.setCityCodes(userService.getCityCodeList(SecurityUtils.getCurrentUsername()));
        Page<AppointmentResponseDto> page = appointmentService.getAppointmentList(appointmentQueryDto,pageable);
        return ResponseEntity.ok(page);
    }

    @PutMapping
    @ApiOperation(value = "编辑预约信息", notes = "编辑预约信息")
    public ResponseEntity<Object> edit (@RequestBody @Validated AppointmentEditDto appointmentEditDto){
        appointmentService.editAppointment(appointmentEditDto);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
